package ca.etsmtl.log720.tp3.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import ca.etsmtl.log720.tp3.dao.Infraction;
import ca.etsmtl.log720.tp3.service.InfractionService;

@Controller
public class InfractionController {

    @Autowired
    private InfractionService infractionService;

    @RequestMapping(value = {"/infraction/show", "/infraction"})
    public String listInfraction(Map<String, Object> map) {
        map.put("infraction", new Infraction());
        map.put("infractionList", infractionService.listInfraction());

        return "infraction";
    }

    @RequestMapping(value = "/infraction/add", method = RequestMethod.POST)
    public String addInfraction(@ModelAttribute("Infraction") Infraction infraction, BindingResult result) {

        infractionService.addInfraction(infraction);

        return "redirect:/infraction";
    }
}
